<?php

/**
 * homepage actions.
 *
 * @package    eveladder
 * @subpackage homepage
 * @author     Your name here
 * @version    SVN: $Id: actions.class.php 2692 2006-11-15 21:03:55Z fabien $
 */
class homepageActions extends sfActions
{
  /**
   * Executes index action
   *
   */
  public function executeIndex()
  {
  	if ($this->getUser()->isAuthenticated())	{
	  	$c = new Criteria() ;
	  	$c->add(ChallengePeer::IS_VALID, 0) ;
	  	$c->add(ChallengePeer::IS_REFUSED, 0) ;
	  	$c->add(ChallengePeer::P2_ID, $this->getUser()->getGuardUser()->getId()) ;
	  	$c->addGroupByColumn(ChallengePeer::P2_ID) ;
	  	$c->addAscendingOrderByColumn(ChallengePeer::CREATED_AT) ;
	  	$this->to_validate = ChallengePeer::doSelectWithPlayers($c) ;
  	}
  	
  	$c = new Criteria() ;
  	$c->add(ChallengePeer::IS_VALID, 1) ;
  	$c->addDescendingOrderByColumn(ChallengePeer::CREATED_AT) ;
  	$c->setLimit(sfConfig::get('app_pager_homepage_challenges')) ;
  	$this->challenges = ChallengePeer::doSelectWithPlayers($c) ;

  	$c = new Criteria() ;
  	$c->addDescendingOrderByColumn(PlayerPeer::POINTS) ;
  	$c->setLimit(sfConfig::get('app_pager_homepage_ranking')) ;
  	$this->ranking = PlayerPeer::doSelectJoinsfGuardUser($c) ;
  }
}
